﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using ConverterInterface;

namespace DelphiConverterLibrary
{
    public class MultilineCommentState : State
    {
        private MultilineCommentState()  { }

        private static MultilineCommentState instance = new MultilineCommentState();

        public static MultilineCommentState Instance
        {
            get {return instance;}
        }

        private char c;

        public override void Execute(DelphiConverter owner)
        {
            if (owner.AvailableChars() <= 0)
            {
                owner.machine.Finished = true;
                owner.machine.ChangeState(NothingState.Instance);
            }
            else
            {
                c = owner.Read();
                owner.machine.Buffer.Append(c);
                if (c == '}')
                {
                    owner.machine.ChangeState(NothingState.Instance);
                }
            }

        }

        public override void Exit(DelphiConverter owner)
        {
            owner.machine.Buffer.Replace("\"", "&quot;");
            owner.machine.Buffer.Replace("<", "&lt;");
            owner.machine.Buffer.Replace(">", "&gt;");
            owner.machine.Buffer.Insert(0, "<span class=\'comment\'>");
            owner.machine.Buffer.Append("</span>");
            owner.FlushBuffer();
        }


    }
}
